﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Sales_DrawPrint : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                ZSql zsql = new ZSql();
                ZSql count = new ZSql();

                string sql = "select brand,comodname,modul,unit,number,typeStock,prices,gifts,guestName,GuestMan,phone,address,TotalMoney,convert(varchar(10),DeliveryDate,120)as ddate,SalesContent,convert(varchar(10),C_date,120)as date from CS_Sales  a join CS_Guest b on a.guestid=b.GuestId where SalesCode='" + Request.QueryString["id"].ToString() + "'";
                count.Open("select sum(number)as num,sum(TotalMoney)as price from CS_Sales where SalesCode='" + Request["id"] + "' group by SalesCode");

                zsql.Open(sql);
                DataTable dt = new DataTable();
                string strTable = "";
                dt = zsql.m_table;
                int a = 0;
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        strTable += "<div><div align=\"center\">重庆市南川区协和家电有限公司</div></div><div><div align=\"center\">销售单</div></div>";
                        strTable += "<table width=\"100%\" ><tr><td width=\"193\" align=\"right\">用户姓名：</td><td width=\"175\">" + zsql.m_table.Rows[0]["GuestMan"].ToString() + "</td><td width=\"225\" align=\"right\">联系电话：</td><td width=\"354\">" + zsql.m_table.Rows[0]["phone"].ToString() + "</td></tr><tr><td align=\"right\">联系地址：</td><td>" + zsql.m_table.Rows[0]["address"].ToString() + "</td><td align=\"right\">送货日期：</td><td>" + zsql.m_table.Rows[0]["DeliveryDate"].ToString() + "</td></tr></table>";


                        strTable += "<table width=\"97%\" border=\"1\"><tr><td align=\"center\">品牌</td><td align=\"center\">规格及型号</td><td align=\"center\">入库类型</td><td align=\"center\">数量</td><td align=\"center\">单位</td><td align=\"center\">单价</td><td align=\"center\">金额</td><td align=\"center\">备注</td></tr>";
                        for (int i = 0; i < zsql.m_table.Rows.Count; i++)
                        {
                            strTable += "<tr><td align=\"center\">" + zsql.m_table.Rows[i]["brand"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["modul"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["typeStock"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["number"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["unit"].ToString() + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["prices"].ToString().Substring(0, zsql.m_table.Rows[i]["prices"].ToString().Length - 2) + "</td><td align=\"center\">" + zsql.m_table.Rows[i]["TotalMoney"].ToString().Substring(0, zsql.m_table.Rows[i]["TotalMoney"].ToString().Length - 2) + "</td><td></td></tr>";
                            a++;
                        }

                        if (a == 1)
                        {
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                        }
                        if (a == 2)
                        {
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                        }
                        if (a == 3)
                        {
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                        }
                        if (a == 4)
                        {
                            strTable += "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                        }
                        strTable += " <tr><th colspan=\"2\">本页小计</th><td colspan=\"3\">" + count.m_table.Rows[0]["num"].ToString() + "</td><td colspan=\"2\">" + count.m_table.Rows[0]["price"].ToString().Substring(0, count.m_table.Rows[0]["price"].ToString().Length - 2) + "</td></tr><tr><th colspan=\"2\">本单合计</th><td colspan=\"3\">" + count.m_table.Rows[0]["num"].ToString() + "</td><td colspan=\"2\">" + count.m_table.Rows[0]["price"].ToString().Substring(0, count.m_table.Rows[0]["price"].ToString().Length - 2) + "</td></tr></table>";

                        if (!string.IsNullOrEmpty(zsql.m_table.Rows[0]["gifts"].ToString()))
                        {


                            strTable += "<table width=\"100%\" border=\"0\"><tr><td width=\"7%\">礼品：</td><td width=\"46%\">" + zsql.m_table.Rows[0]["gifts"].ToString() + "</td><td width=\"10%\">注：赠品</td><td width=\"37%\"></td> </tr></table>";
                        }

                        strTable += "<table width=\"97%\" border=\"1\"><tr><td colspan=\"8\"><font color=\"#FF0000\"><p>注：请用户仔细核对商品，是否与您购买的商品一致.外观是否完好.附属配件.数量是否齐全。</p></font></td></tr><tr><td width=\"120\" align=\"right\">服务电话：</td><td width=\"150\">023-71430000</td><td width=\"91\" align=\"right\"></td><td width=\"171\"></td><td width=\"186\" align=\"right\">开票人：</td><td width=\"217\">" + Server.UrlDecode(Request.Cookies["user"].Values["realname"]) + "</td></tr></table>";


                    }
                }
                zsql.Close();
                count.Close();

                lblTable.Text = strTable;
            }
        }
    }
}
